package com.example.concurrentprogramming8016.thread.notify;

import ch.qos.logback.core.net.ssl.SSL;

/**
 * @author liyanhao
 * @Date 2023-02-08 0:20
 */
public class NotifyDemo {
    private static Object lock = new Object();
    private static boolean flag = true;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (lock) {
                while (flag) {
                    System.out.println("wait start ...");
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("wait end ...");
            }
        }, "t1");
        t1.start();

        Thread t2 = new Thread(() -> {
            if (flag) {
                synchronized (lock) {
                    lock.notify();
                    System.out.println("notify...");
                    flag = false;
                }
            }
        }, "t2");
        t2.start();
    }
}
